﻿using TaskMasterByQuartz.Domain.Enums;
using TaskMasterByQuartz.Domain.InterfaceRepository;

namespace TaskMasterByQuartz.Domain.ServiceRepository
{
    public class SchedulerDomainService
    {
        private readonly ISchedulerCenter schedulerCenter;

        public SchedulerDomainService(ISchedulerCenter schedulerCenter)
        {
            this.schedulerCenter = schedulerCenter;
        }

        /// <summary>
        /// 添加一个工作调度
        /// </summary>
        /// <param name="runNumber"></param>
        /// <returns>是否添加成功</returns>
        public async Task<bool> AddScheduleJobAsync(string jobGroupName,
            string jobName,
            DateTimeOffset? endTime,
            JobTypeEnum jobType,
            string? requestUrl,
            string? headers,
            string? requestParameters,
            RequestTypeEnum? requestType,
            TriggerTypeEnum triggerType,
             string cron, DateTimeOffset beginTime, int? runTimes, int IntervalSecond, string description,
            long? runNumber = null)
        {
            bool checkResult =  await schedulerCenter.CheckScheduleJobAsync(jobGroupName, jobName);
            if (checkResult)
            {
                schedulerCenter.AddScheduleJobAsync(jobGroupName, jobName, endTime, jobType, requestUrl, headers, requestParameters, requestType, triggerType, cron, beginTime, runTimes, IntervalSecond, description, runNumber);
                return true;
            }
            return false;
        }
    }
}
